/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    bool isBalanced(TreeNode* root) {
        if(root==nullptr){return true;}
        return tellBalance(root);
    }
    bool tellBalance(TreeNode* root){
        if(root==nullptr){return true;}
        return tellBalance(root->left) && tellBalance(root->right) && abs(getdepth(root->left)-getdepth(root->right))<=1;
    }
    int getdepth(TreeNode* root){
        if(root==nullptr){return 0;}
        return max(getdepth(root->left),getdepth(root->right))+1;
    }
};